#include "SDLTexture.h"
#include <SDL_image.h>
#include <Renderer/Renderer.h>

namespace Engine2D
{
    SDLTexture::SDLTexture()
        : m_texture(nullptr)
    {
    }

    SDLTexture::SDLTexture(Uint32 format, int access, int w, int h)
    {
        m_texture = SDL_CreateTexture((SDL_Renderer*)Renderer::Instance()->GetRenderer(), format, access, w, h);
    }

    SDLTexture::SDLTexture(SDL_Texture *tex)
        : m_texture(tex)
    {
    }

    bool SDLTexture::Load(const std::string &fileName)
    {
        SDL_Surface * surface = IMG_Load(fileName.c_str());
        if (!surface) {
            return false;
        }
        m_texture = SDL_CreateTextureFromSurface((SDL_Renderer*)Renderer::Instance()->GetRenderer(), surface);
        return true;
    }

    SDLTexture::~SDLTexture()
    {
        SDL_DestroyTexture(m_texture);
    }
} // namespace Engine2D
